<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
 public function index(){//显示首页
      $category=M('category');
     $catelist=$category->where('pid=0')->select();
     foreach ($catelist as $k=>$v)//对一级分类循环
         {
          $catelist[$k]['child']=fenlei($v['cid']);
       }
     $this->assign("catelist",$catelist);
  //获取推荐的商品，两个条件，回收站no，推荐标志为yes
    $best=M('goods');
  $bestlist=$best->where("recycle='no'and is_best='yes'")->limit(3)->select();
       $this->assign("bestlist",$bestlist);
      $this->display();
   }
  public function goods(){//显示商品的详细信息
    $gid=I("get.gid",0);
    $goods=M('goods');
    $goodslists=$goods->where("gid=$gid")->find();
    //获得商品的1.2.3级分类
    $cid=$goodslists['cid'];
    $types=D("Category")->getPidList($cid);
    //获取商品的属性
    $attr=D("GoodsAttr")->getData($cid,$gid);
    $this->assign("types",$types);
    $this->assign("goodslists",$goodslists);//$lists是二维数组
    $this->assign("attr",$attr);
    $this->display();
  }
  public function find(){
      //获取参数
     $cid=I('get.cid',0);
     //查询cid的分类名称 
     $cname=M('category')->where("cid=$cid")->getField('cname');
     
     $gdata=D('Goods')->getByFilter(
             'gid,gname,price,thumb',
             array("cid"=>$cid)
             );
     $this->assign('gdata',$gdata);
     $this->assign('cname',$cname);
     $this->display();
  }
}